package com.shanlitech.bluetooth.map;

import android.graphics.Rect;
import android.util.Log;

import com.shanlitech.lbs.geometry.Rectangle;

public class VisibleChecker {
    // 几何坐标系Y轴向上，屏幕坐标系Y轴向下
    private static final String TAG = "Map2D";
    private Rectangle visible;

    public void setVisibleRect(Rect rect) {
        this.visible = new Rectangle(rect.left,- rect.top,rect.right, - rect.bottom);
    }

    public boolean visiblePoint(float x, float y) {
        if( visible != null ) {
            return visible.isContainsPoint(x,-y);
        }
        return false;
    }

    public boolean visibleRound(float x,float y,float r) {
        if( visible != null ) {
            return visible.isCircleIntersected(x,-y,r);
        }
        return false;
    }

    public boolean visibleSegment(float x1,float y1,float x2,float y2) {
        if( visible != null ) {
            return visible.isIntersected(x1,-y1,x2,-y2);
        }
        return false;
    }

    public boolean visibleRect(Rect rect) {
        if( visible != null ) {
            return ! (
                    rect.right < visible.left
                    || rect.left > visible.right
                    || rect.top > - visible.bottom
                    || rect.bottom < - visible.top
                    );
        }
        return false;
    }
}
